﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MINERP.MODEL.FoundationModel;
using System.Data;

using Microsoft.Practices.EnterpriseLibrary.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data.Common;

namespace MINERP.DAL.Statistics
{
    /// <summary>
    /// 统计设计人员业绩的DAL
    /// </summary>
    public class UserDesignerStatDAL
    {
        public static List<Tb_WorkerGroup_Info> GetAllGroup()
        {
            List<Tb_WorkerGroup_Info> groupList = new List<Tb_WorkerGroup_Info>();

            using (newSampleYPDBEntities db=new newSampleYPDBEntities ())
            {
                foreach (var item in db.tb_WorkerGroup.ToList())
                {
                    groupList.Add(new Tb_WorkerGroup_Info() {GroupId=item.GroupId,GroupName=item.GroupName });
                }
            }

            return groupList;
        }

        /// <summary>
        /// 得到设计的钱
        /// </summary>
        /// <param name="groupId"></param>
        /// <param name="startTime"></param>
        /// <param name="endTime"></param>
        /// <returns></returns>
        public static DataSet GetStat(int groupId, DateTime startTime, DateTime endTime)
        {
            DataSet dsResult = new DataSet();
            Database db = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = db.GetStoredProcCommand("GetDesignerPirce");
            dbCommand.CommandTimeout = 120;
            db.AddInParameter(dbCommand, "groupId", DbType.Int32, groupId);
            db.AddInParameter(dbCommand, "startTime", DbType.DateTime, startTime);
            db.AddInParameter(dbCommand, "endTime", DbType.DateTime, endTime);

            try
            {
               dsResult= db.ExecuteDataSet(dbCommand);
            }
            catch (Exception)
            {
                return null;
            }

            return dsResult;
        }
    }
}
